﻿using System.Windows.Forms;

namespace PiControls.Controls.DriveUI.TCPClient
{
    public partial class TcpClientConfig: UserControl
    {
        private string IP = "127.0.0.1"; // 默认IP地址
        private string ObjectName = "TCPClient"; // 默认对象名称
        private int port = 8080; // 默认端口号
        private bool runIsConnected  = false; // 是否已连接

        public void setIP(string ip)
        {
            IP = ip;
            textBoxIP.Text = IP;
        }

        public void setPort(int port)
        {
            this.port = port;
            textBoxPort.Text = port.ToString();
        }

        public  void setRunIsConnected(bool isConnected)
        {
            runIsConnected = isConnected;
            piSwitchAppRunOpen.L_IsOpen = runIsConnected;
        }

        public void setObjectName(string objectName)
        {
            ObjectName = objectName;
            textBoxObjectName.Text = ObjectName;
        }

        public string getIP()
        {
            return IP;
        }

        public int getPort()
        {
            return port;
        }

        public bool getRunIsConnected()
        {
            return runIsConnected;
        }

        public string getObjectName()
        {

            return ObjectName;
        }        

        public TcpClientConfig()
        {
            InitializeComponent();
        }


        public bool saveConfig()
        {
            if (textBoxIP.Text == "")
            {
                MessageBox.Show("IP不能为空！");
                return false;
            }
            if (textBoxPort.Text == "")
            {
                MessageBox.Show("端口号不能为空！");
                return false;
            }
            if (textBoxObjectName.Text == "")
            {
                MessageBox.Show("对象名称不能为空！");
                return false; 
            }
            IP = textBoxIP.Text;
            port = int.Parse(textBoxPort.Text);
            runIsConnected = piSwitchAppRunOpen.L_IsOpen;
            ObjectName = textBoxObjectName.Text;
            return true; 
        }
    }
}
